"use strict";
// pages/room/edit.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    relaid: 0,
    name: "",
    role: "",
    default_roomid:"",
    is_active: true,
    classfee:1,
    open_paper:false,
    is_superuser:false,
    remark:""
  },
  refreshInfo: function() {
    if (this.data.relaid > 0){
      app.api.api_user_edit_info({ relaid: this.data.relaid}).then(res => {
        this.setData({
          name: res.name,
          role: res.role,
          default_roomid: res.default_roomid,
          is_active: res.is_active,
          open_paper: res.open_paper,
          classfee: res.classfee,
          is_superuser: res.is_superuser,
          remark:res.remark
        })
      })
    }
  },
  is_active_change: function(e){
    this.setData({ is_active: e.detail.value })
  },
  is_superuser_change: function (e) {
    this.setData({ is_superuser: e.detail.value })
  },
  open_paper_change: function (e) {
    this.setData({ open_paper: e.detail.value })
  },
  bindKeyInput: function(e) {
    this.data[e.currentTarget.dataset.obj] = e.detail.value
  },
  save: function() {
    app.api.api_user_edit_save({
        relaid: this.data.relaid,
        name: this.data.name,
        role: this.data.role,
        default_roomid: this.data.default_roomid,
        is_active: this.data.is_active,
        is_superuser: this.data.is_superuser,
        open_paper: this.data.open_paper,
        classfee: this.data.classfee,
        remark: this.remark
      }).then(res => {
        wx.navigateBack()
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let relaid = options.relaid
    if(relaid){
      this.setData({ relaid: parseInt(relaid)})
      this.refreshInfo()
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.refreshInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})